package cn.tedu.log.utils;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;

@Setter
@Getter
@NoArgsConstructor
public class JsonResult {
    private Integer code;
    private String msg;
    private Object data;

    public JsonResult(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 第3个构造方法：只有 状态码和描述;
     * 应用场景：用于不需要返回具体数据的功能
     */
    public JsonResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = new ArrayList<>();
    }

    /**
     * 第5个构造方法：StatusCode和具体数据data;
     * 应用场景：有具体数据返回的功能;
     */
    public JsonResult(Integer code, Object data) {
        this.code = code;
        this.msg = "操作成功";
        this.data = data;
    }

    /**
     * 第6个构造方法：用于静态方法中快速构建JsonResult对象
     * 应用场景：所有操作成功的功能
     */
    public JsonResult(Object data) {
        this.code = 200;
        this.msg = "操作成功";
        this.data = data;
    }

    /**
     * 定义2个静态方法,用于快速生成 JsonResult 对象
     */
    public static JsonResult ok(Object data) {
        return new JsonResult(data);
    }

    public static JsonResult ok() {
        return ok(200, "操作成功", new ArrayList<Object>());
    }

    public static JsonResult ok(Integer code, String msg) {
        return new JsonResult(code, msg);
    }

    public static JsonResult ok(String msg, Object data) {
        return new JsonResult(200, msg, data);
    }

    public static JsonResult ok(Integer code, String msg, Object data) {
        return new JsonResult(code, msg, data);
    }
}